﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace M2Image
{
    /// <summary>
    /// 一些通用函数、属性，包括一些Delphi与.NET的数据转换工具方法
    /// </summary>
    internal static class Delphi
    {

        /// <summary>
        /// Delphi 8位BMP图调色板，如果因设备不支持透明色可将调色板第一个颜色置为背景色，如-16777216表示黑色
        /// </summary>
        //public readonly static const int[] PALLETE = { 0, -8388608, -16744448, -8355840, -16777088, -8388480, -16744320, -4144960, -11173737, -6440504, -8686733, -13817559, -10857902, -10266022, -12437191, -14870504, -15200240, -14084072, -15726584, -886415, -2005153, -42406, -52943, -2729390, -7073792, -7067368, -13039616, -9236480, -4909056, -4365486, -12445680, -21863, -10874880, -9225943, -5944783, -7046285, -4369871, -11394800, -8703720, -13821936, -7583183, -7067392, -4378368, -3771566, -9752296, -3773630, -3257856, -5938375, -10866408, -14020608, -15398912, -12969984, -16252928, -14090240, -11927552, -6488064, -2359296, -2228224, -327680, -6524078, -7050422, -9221591, -11390696, -7583208, -7846895, -11919104, -14608368, -2714534, -3773663, -1086720, -35072, -5925756, -12439263, -15200248, -14084088, -14610432, -13031144, -7576775, -12441328, -9747944, -8697320, -7058944, -7568261, -9739430, -11910599, -14081768, -12175063, -4872812, -8688806, -3231340, -5927821, -7572646, -4877197, -2710157, -1071798, -1063284, -8690878, -9742791, -4352934, -10274560, -2701651, -11386327, -7052520, -1059155, -5927837, -10266038, -4348549, -10862056, -4355023, -13291223, -7043997, -8688822, -5927846, -10859991, -6522055, -12439280, -1069791, -15200256, -14081792, -6526208, -7044006, -11386344, -9741783, -8690911, -6522079, -2185984, -10857927, -13555440, -3228293, -10266055, -7044022, -3758807, -15688680, -12415926, -13530046, -15690711, -16246768, -16246760, -16242416, -15187415, -5917267, -9735309, -15193815, -15187382, -13548982, -10238242, -12263937, -7547153, -9213127, -532935, -528500, -530688, -9737382, -10842971, -12995089, -11887410, -13531979, -13544853, -2171178, -4342347, -7566204, -526370, -16775144, -16246727, -16248791, -16246784, -16242432, -16756059, -16745506, -15718070, -15713941, -15707508, -14591323, -15716006, -15711612, -13544828, -15195855, -11904389, -11375707, -14075549, -15709474, -14079711, -11908551, -14079720, -11908567, -8684734, -6513590, -10855895, -12434924, -13027072, -10921728, -3525332, -9735391, -14077696, -13551344, -13551336, -12432896, -11377896, -10849495, -13546984, -15195904, -15191808, -15189744, -10255286, -9716406, -10242742, -10240694, -10838966, -11891655, -10238390, -10234294, -11369398, -13536471, -10238374, -11354806, -15663360, -15193832, -11892662, -11868342, -16754176, -16742400, -16739328, -16720384, -16716288, -16712960, -11904364, -10259531, -8680234, -9733162, -8943361, -3750194, -7039844, -6515514, -13553351, -14083964, -15204220, -11910574, -11386245, -10265997, -3230217, -7570532, -8969524, -2249985, -1002454, -2162529, -1894477, -1040, -6250332, -8355712, -65536, -16711936, -256, -16776961, -65281, -16711681, -1 };
        public static float[][] PALLETE = { new float[] { 1f, 0f, 0f, 0f }, new float[] { 1f, 0.5019608f, 0f, 0f }, new float[] { 1f, 0f, 0.5019608f, 0f }, new float[] { 1f, 0.5019608f, 0.5019608f, 0f }, new float[] { 1f, 0f, 0f, 0.5019608f }, new float[] { 1f, 0.5019608f, 0f, 0.5019608f }, new float[] { 1f, 0f, 0.5019608f, 0.5019608f }, new float[] { 1f, 0.7529412f, 0.7529412f, 0.7529412f }, new float[] { 1f, 0.3333333f, 0.5019608f, 0.5921569f }, new float[] { 1f, 0.6156863f, 0.7254902f, 0.7843137f }, new float[] { 1f, 0.4823529f, 0.4509804f, 0.4509804f }, new float[] { 1f, 0.1764706f, 0.1607843f, 0.1607843f }, new float[] { 1f, 0.3529412f, 0.3215686f, 0.3215686f }, new float[] { 1f, 0.3882353f, 0.3529412f, 0.3529412f }, new float[] { 1f, 0.2588235f, 0.2235294f, 0.2235294f }, new float[] { 1f, 0.1137255f, 0.09411765f, 0.09411765f }, new float[] { 1f, 0.09411765f, 0.0627451f, 0.0627451f }, new float[] { 1f, 0.1607843f, 0.09411765f, 0.09411765f }, new float[] { 1f, 0.0627451f, 0.03137255f, 0.03137255f }, new float[] { 1f, 0.9490196f, 0.4745098f, 0.4431373f }, new float[] { 1f, 0.8823529f, 0.4039216f, 0.372549f }, new float[] { 1f, 1f, 0.3529412f, 0.3529412f }, new float[] { 1f, 1f, 0.1921569f, 0.1921569f }, new float[] { 1f, 0.8392157f, 0.3529412f, 0.3215686f }, new float[] { 1f, 0.5803922f, 0.0627451f, 0f }, new float[] { 1f, 0.5803922f, 0.1607843f, 0.09411765f }, new float[] { 1f, 0.2235294f, 0.03137255f, 0f }, new float[] { 1f, 0.4509804f, 0.0627451f, 0f }, new float[] { 1f, 0.7098039f, 0.09411765f, 0f }, new float[] { 1f, 0.7411765f, 0.3882353f, 0.3215686f }, new float[] { 1f, 0.2588235f, 0.09411765f, 0.0627451f }, new float[] { 1f, 1f, 0.6666667f, 0.6f }, new float[] { 1f, 0.3529412f, 0.0627451f, 0f }, new float[] { 1f, 0.4509804f, 0.2235294f, 0.1607843f }, new float[] { 1f, 0.6470588f, 0.2901961f, 0.1921569f }, new float[] { 1f, 0.5803922f, 0.4823529f, 0.4509804f }, new float[] { 1f, 0.7411765f, 0.3215686f, 0.1921569f }, new float[] { 1f, 0.3215686f, 0.1294118f, 0.0627451f }, new float[] { 1f, 0.4823529f, 0.1921569f, 0.09411765f }, new float[] { 1f, 0.1764706f, 0.09411765f, 0.0627451f }, new float[] { 1f, 0.5490196f, 0.2901961f, 0.1921569f }, new float[] { 1f, 0.5803922f, 0.1607843f, 0f }, new float[] { 1f, 0.7411765f, 0.1921569f, 0f }, new float[] { 1f, 0.7764706f, 0.4509804f, 0.3215686f }, new float[] { 1f, 0.4196078f, 0.1921569f, 0.09411765f }, new float[] { 1f, 0.7764706f, 0.4196078f, 0.2588235f }, new float[] { 1f, 0.8078431f, 0.2901961f, 0f }, new float[] { 1f, 0.6470588f, 0.3882353f, 0.2235294f }, new float[] { 1f, 0.3529412f, 0.1921569f, 0.09411765f }, new float[] { 1f, 0.1647059f, 0.0627451f, 0f }, new float[] { 1f, 0.08235294f, 0.03137255f, 0f }, new float[] { 1f, 0.227451f, 0.09411765f, 0f }, new float[] { 1f, 0.03137255f, 0f, 0f }, new float[] { 1f, 0.1607843f, 0f, 0f }, new float[] { 1f, 0.2901961f, 0f, 0f }, new float[] { 1f, 0.6156863f, 0f, 0f }, new float[] { 1f, 0.8627451f, 0f, 0f }, new float[] { 1f, 0.8705882f, 0f, 0f }, new float[] { 1f, 0.9843137f, 0f, 0f }, new float[] { 1f, 0.6117647f, 0.4509804f, 0.3215686f }, new float[] { 1f, 0.5803922f, 0.4196078f, 0.2901961f }, new float[] { 1f, 0.4509804f, 0.2901961f, 0.1607843f }, new float[] { 1f, 0.3215686f, 0.1921569f, 0.09411765f }, new float[] { 1f, 0.5490196f, 0.2901961f, 0.09411765f }, new float[] { 1f, 0.5333334f, 0.2666667f, 0.06666667f }, new float[] { 1f, 0.2901961f, 0.1294118f, 0f }, new float[] { 1f, 0.1294118f, 0.09411765f, 0.0627451f }, new float[] { 1f, 0.8392157f, 0.5803922f, 0.3529412f }, new float[] { 1f, 0.7764706f, 0.4196078f, 0.1294118f }, new float[] { 1f, 0.9372549f, 0.4196078f, 0f }, new float[] { 1f, 1f, 0.4666667f, 0f }, new float[] { 1f, 0.6470588f, 0.5803922f, 0.5176471f }, new float[] { 1f, 0.2588235f, 0.1921569f, 0.1294118f }, new float[] { 1f, 0.09411765f, 0.0627451f, 0.03137255f }, new float[] { 1f, 0.1607843f, 0.09411765f, 0.03137255f }, new float[] { 1f, 0.1294118f, 0.0627451f, 0f }, new float[] { 1f, 0.2235294f, 0.1607843f, 0.09411765f }, new float[] { 1f, 0.5490196f, 0.3882353f, 0.2235294f }, new float[] { 1f, 0.2588235f, 0.1607843f, 0.0627451f }, new float[] { 1f, 0.4196078f, 0.2588235f, 0.09411765f }, new float[] { 1f, 0.4823529f, 0.2901961f, 0.09411765f }, new float[] { 1f, 0.5803922f, 0.2901961f, 0f }, new float[] { 1f, 0.5490196f, 0.5176471f, 0.4823529f }, new float[] { 1f, 0.4196078f, 0.3882353f, 0.3529412f }, new float[] { 1f, 0.2901961f, 0.2588235f, 0.2235294f }, new float[] { 1f, 0.1607843f, 0.1294118f, 0.09411765f }, new float[] { 1f, 0.2745098f, 0.2235294f, 0.1607843f }, new float[] { 1f, 0.7098039f, 0.6470588f, 0.5803922f }, new float[] { 1f, 0.4823529f, 0.4196078f, 0.3529412f }, new float[] { 1f, 0.8078431f, 0.6941177f, 0.5803922f }, new float[] { 1f, 0.6470588f, 0.5490196f, 0.4509804f }, new float[] { 1f, 0.5490196f, 0.4509804f, 0.3529412f }, new float[] { 1f, 0.7098039f, 0.5803922f, 0.4509804f }, new float[] { 1f, 0.8392157f, 0.6470588f, 0.4509804f }, new float[] { 1f, 0.9372549f, 0.6470588f, 0.2901961f }, new float[] { 1f, 0.9372549f, 0.7764706f, 0.5490196f }, new float[] { 1f, 0.4823529f, 0.3882353f, 0.2588235f }, new float[] { 1f, 0.4196078f, 0.3372549f, 0.2235294f }, new float[] { 1f, 0.7411765f, 0.5803922f, 0.3529412f }, new float[] { 1f, 0.3882353f, 0.2235294f, 0f }, new float[] { 1f, 0.8392157f, 0.7764706f, 0.6784314f }, new float[] { 1f, 0.3215686f, 0.2588235f, 0.1607843f }, new float[] { 1f, 0.5803922f, 0.3882353f, 0.09411765f }, new float[] { 1f, 0.9372549f, 0.8392157f, 0.6784314f }, new float[] { 1f, 0.6470588f, 0.5490196f, 0.3882353f }, new float[] { 1f, 0.3882353f, 0.3529412f, 0.2901961f }, new float[] { 1f, 0.7411765f, 0.6470588f, 0.4823529f }, new float[] { 1f, 0.3529412f, 0.2588235f, 0.09411765f }, new float[] { 1f, 0.7411765f, 0.5490196f, 0.1921569f }, new float[] { 1f, 0.2078431f, 0.1921569f, 0.1607843f }, new float[] { 1f, 0.5803922f, 0.5176471f, 0.3882353f }, new float[] { 1f, 0.4823529f, 0.4196078f, 0.2901961f }, new float[] { 1f, 0.6470588f, 0.5490196f, 0.3529412f }, new float[] { 1f, 0.3529412f, 0.2901961f, 0.1607843f }, new float[] { 1f, 0.6117647f, 0.4823529f, 0.2235294f }, new float[] { 1f, 0.2588235f, 0.1921569f, 0.0627451f }, new float[] { 1f, 0.9372549f, 0.6784314f, 0.1294118f }, new float[] { 1f, 0.09411765f, 0.0627451f, 0f }, new float[] { 1f, 0.1607843f, 0.1294118f, 0f }, new float[] { 1f, 0.6117647f, 0.4196078f, 0f }, new float[] { 1f, 0.5803922f, 0.5176471f, 0.3529412f }, new float[] { 1f, 0.3215686f, 0.2588235f, 0.09411765f }, new float[] { 1f, 0.4196078f, 0.3529412f, 0.1607843f }, new float[] { 1f, 0.4823529f, 0.3882353f, 0.1294118f }, new float[] { 1f, 0.6117647f, 0.4823529f, 0.1294118f }, new float[] { 1f, 0.8705882f, 0.6470588f, 0f }, new float[] { 1f, 0.3529412f, 0.3215686f, 0.2235294f }, new float[] { 1f, 0.1921569f, 0.1607843f, 0.0627451f }, new float[] { 1f, 0.8078431f, 0.7411765f, 0.4823529f }, new float[] { 1f, 0.3882353f, 0.3529412f, 0.2235294f }, new float[] { 1f, 0.5803922f, 0.5176471f, 0.2901961f }, new float[] { 1f, 0.7764706f, 0.6470588f, 0.1607843f }, new float[] { 1f, 0.0627451f, 0.6117647f, 0.09411765f }, new float[] { 1f, 0.2588235f, 0.5490196f, 0.2901961f }, new float[] { 1f, 0.1921569f, 0.5490196f, 0.2588235f }, new float[] { 1f, 0.0627451f, 0.5803922f, 0.1607843f }, new float[] { 1f, 0.03137255f, 0.09411765f, 0.0627451f }, new float[] { 1f, 0.03137255f, 0.09411765f, 0.09411765f }, new float[] { 1f, 0.03137255f, 0.1607843f, 0.0627451f }, new float[] { 1f, 0.09411765f, 0.2588235f, 0.1607843f }, new float[] { 1f, 0.6470588f, 0.7098039f, 0.6784314f }, new float[] { 1f, 0.4196078f, 0.4509804f, 0.4509804f }, new float[] { 1f, 0.09411765f, 0.1607843f, 0.1607843f }, new float[] { 1f, 0.09411765f, 0.2588235f, 0.2901961f }, new float[] { 1f, 0.1921569f, 0.2588235f, 0.2901961f }, new float[] { 1f, 0.3882353f, 0.7764706f, 0.8705882f }, new float[] { 1f, 0.2666667f, 0.8666667f, 1f }, new float[] { 1f, 0.5490196f, 0.8392157f, 0.9372549f }, new float[] { 1f, 0.4509804f, 0.4196078f, 0.2235294f }, new float[] { 1f, 0.9686275f, 0.8705882f, 0.2235294f }, new float[] { 1f, 0.9686275f, 0.9372549f, 0.5490196f }, new float[] { 1f, 0.9686275f, 0.9058824f, 0f }, new float[] { 1f, 0.4196078f, 0.4196078f, 0.3529412f }, new float[] { 1f, 0.3529412f, 0.5490196f, 0.6470588f }, new float[] { 1f, 0.2235294f, 0.7098039f, 0.9372549f }, new float[] { 1f, 0.2901961f, 0.6117647f, 0.8078431f }, new float[] { 1f, 0.1921569f, 0.5176471f, 0.7098039f }, new float[] { 1f, 0.1921569f, 0.3215686f, 0.4196078f }, new float[] { 1f, 0.8705882f, 0.8705882f, 0.8392157f }, new float[] { 1f, 0.7411765f, 0.7411765f, 0.7098039f }, new float[] { 1f, 0.5490196f, 0.5490196f, 0.5176471f }, new float[] { 1f, 0.9686275f, 0.9686275f, 0.8705882f }, new float[] { 1f, 0f, 0.03137255f, 0.09411765f }, new float[] { 1f, 0.03137255f, 0.09411765f, 0.2235294f }, new float[] { 1f, 0.03137255f, 0.0627451f, 0.1607843f }, new float[] { 1f, 0.03137255f, 0.09411765f, 0f }, new float[] { 1f, 0.03137255f, 0.1607843f, 0f }, new float[] { 1f, 0f, 0.3215686f, 0.6470588f }, new float[] { 1f, 0f, 0.4823529f, 0.8705882f }, new float[] { 1f, 0.0627451f, 0.1607843f, 0.2901961f }, new float[] { 1f, 0.0627451f, 0.2235294f, 0.4196078f }, new float[] { 1f, 0.0627451f, 0.3215686f, 0.5490196f }, new float[] { 1f, 0.1294118f, 0.3529412f, 0.6470588f }, new float[] { 1f, 0.0627451f, 0.1921569f, 0.3529412f }, new float[] { 1f, 0.0627451f, 0.2588235f, 0.5176471f }, new float[] { 1f, 0.1921569f, 0.3215686f, 0.5176471f }, new float[] { 1f, 0.09411765f, 0.1294118f, 0.1921569f }, new float[] { 1f, 0.2901961f, 0.3529412f, 0.4823529f }, new float[] { 1f, 0.3215686f, 0.4196078f, 0.6470588f }, new float[] { 1f, 0.1607843f, 0.2235294f, 0.3882353f }, new float[] { 1f, 0.0627451f, 0.2901961f, 0.8705882f }, new float[] { 1f, 0.1607843f, 0.1607843f, 0.1294118f }, new float[] { 1f, 0.2901961f, 0.2901961f, 0.2235294f }, new float[] { 1f, 0.1607843f, 0.1607843f, 0.09411765f }, new float[] { 1f, 0.2901961f, 0.2901961f, 0.1607843f }, new float[] { 1f, 0.4823529f, 0.4823529f, 0.2588235f }, new float[] { 1f, 0.6117647f, 0.6117647f, 0.2901961f }, new float[] { 1f, 0.3529412f, 0.3529412f, 0.1607843f }, new float[] { 1f, 0.2588235f, 0.2588235f, 0.07843138f }, new float[] { 1f, 0.2235294f, 0.2235294f, 0f }, new float[] { 1f, 0.3490196f, 0.3490196f, 0f }, new float[] { 1f, 0.7921569f, 0.2078431f, 0.172549f }, new float[] { 1f, 0.4196078f, 0.4509804f, 0.1294118f }, new float[] { 1f, 0.1607843f, 0.1921569f, 0f }, new float[] { 1f, 0.1921569f, 0.2235294f, 0.0627451f }, new float[] { 1f, 0.1921569f, 0.2235294f, 0.09411765f }, new float[] { 1f, 0.2588235f, 0.2901961f, 0f }, new float[] { 1f, 0.3215686f, 0.3882353f, 0.09411765f }, new float[] { 1f, 0.3529412f, 0.4509804f, 0.1607843f }, new float[] { 1f, 0.1921569f, 0.2901961f, 0.09411765f }, new float[] { 1f, 0.09411765f, 0.1294118f, 0f }, new float[] { 1f, 0.09411765f, 0.1921569f, 0f }, new float[] { 1f, 0.09411765f, 0.2235294f, 0.0627451f }, new float[] { 1f, 0.3882353f, 0.5176471f, 0.2901961f }, new float[] { 1f, 0.4196078f, 0.7411765f, 0.2901961f }, new float[] { 1f, 0.3882353f, 0.7098039f, 0.2901961f }, new float[] { 1f, 0.3882353f, 0.7411765f, 0.2901961f }, new float[] { 1f, 0.3529412f, 0.6117647f, 0.2901961f }, new float[] { 1f, 0.2901961f, 0.5490196f, 0.2235294f }, new float[] { 1f, 0.3882353f, 0.7764706f, 0.2901961f }, new float[] { 1f, 0.3882353f, 0.8392157f, 0.2901961f }, new float[] { 1f, 0.3215686f, 0.5176471f, 0.2901961f }, new float[] { 1f, 0.1921569f, 0.4509804f, 0.1607843f }, new float[] { 1f, 0.3882353f, 0.7764706f, 0.3529412f }, new float[] { 1f, 0.3215686f, 0.7411765f, 0.2901961f }, new float[] { 1f, 0.0627451f, 1f, 0f }, new float[] { 1f, 0.09411765f, 0.1607843f, 0.09411765f }, new float[] { 1f, 0.2901961f, 0.5333334f, 0.2901961f }, new float[] { 1f, 0.2901961f, 0.9058824f, 0.2901961f }, new float[] { 1f, 0f, 0.3529412f, 0f }, new float[] { 1f, 0f, 0.5333334f, 0f }, new float[] { 1f, 0f, 0.5803922f, 0f }, new float[] { 1f, 0f, 0.8705882f, 0f }, new float[] { 1f, 0f, 0.9333333f, 0f }, new float[] { 1f, 0f, 0.9843137f, 0f }, new float[] { 1f, 0.2901961f, 0.3529412f, 0.5803922f }, new float[] { 1f, 0.3882353f, 0.4509804f, 0.7098039f }, new float[] { 1f, 0.4823529f, 0.5490196f, 0.8392157f }, new float[] { 1f, 0.4196078f, 0.4823529f, 0.8392157f }, new float[] { 1f, 0.4666667f, 0.5333334f, 1f }, new float[] { 1f, 0.7764706f, 0.7764706f, 0.8078431f }, new float[] { 1f, 0.5803922f, 0.5803922f, 0.6117647f }, new float[] { 1f, 0.6117647f, 0.5803922f, 0.7764706f }, new float[] { 1f, 0.1921569f, 0.1921569f, 0.2235294f }, new float[] { 1f, 0.1607843f, 0.09411765f, 0.5176471f }, new float[] { 1f, 0.09411765f, 0f, 0.5176471f }, new float[] { 1f, 0.2901961f, 0.2588235f, 0.3215686f }, new float[] { 1f, 0.3215686f, 0.2588235f, 0.4823529f }, new float[] { 1f, 0.3882353f, 0.3529412f, 0.4509804f }, new float[] { 1f, 0.8078431f, 0.7098039f, 0.9686275f }, new float[] { 1f, 0.5490196f, 0.4823529f, 0.6117647f }, new float[] { 1f, 0.4666667f, 0.1333333f, 0.8f }, new float[] { 1f, 0.8666667f, 0.6666667f, 1f }, new float[] { 1f, 0.9411765f, 0.7058824f, 0.1647059f }, new float[] { 1f, 0.8745098f, 0f, 0.6235294f }, new float[] { 1f, 0.8901961f, 0.09019608f, 0.7019608f }, new float[] { 1f, 1f, 0.9843137f, 0.9411765f }, new float[] { 1f, 0.627451f, 0.627451f, 0.6431373f }, new float[] { 1f, 0.5019608f, 0.5019608f, 0.5019608f }, new float[] { 1f, 1f, 0f, 0f }, new float[] { 1f, 0f, 1f, 0f }, new float[] { 1f, 1f, 1f, 0f }, new float[] { 1f, 0f, 0f, 1f }, new float[] { 1f, 1f, 0f, 1f }, new float[] { 1f, 0f, 1f, 1f }, new float[] { 1f, 1f, 1f, 1f } };

        /// <summary>
        /// 将Pascal语言序列化的TDateTime对象反序列化为.NET的DateTime对象
        /// <para>TDateTime使用一个Double数据存储时间日期，整数部分为1899年12月30日至今的天数，小数部分为当天已过比例(比如1点就是1/24)</para>
        /// </summary>
        /// <param name="reader">数据读取器</param>
        /// <returns>反序列化的时间日期对象</returns>
        internal static DateTime ReadDate(BinaryReader reader)
        {
            double timeDb = reader.ReadDouble();
            int days = (int)timeDb;
            double ratio = Math.Abs(timeDb - days);
            DateTime result = new DateTime(1899, 12, 30, 0, 0, 0);
            result.AddDays(days);
            result.AddMilliseconds((int)(24 * 60 * 60 * 1000 * ratio));
            return result;
        }

        /// <summary>
        /// 对于bmp图片填充字节进行补足
        /// </summary>
        /// <param name="bitCount">每行图片色彩值字节位数(bit)</param>
        /// <returns>每行图片色彩数据占字节数(byte)</returns>
        internal static int WidthBytes(int bitCount)
        {
            return (bitCount + 31) / 32 * 4;
        }

        /// <summary>
        /// 计算bmp图片逐行读取时需要跳过的字节数
        /// <para>即用该行实际占用的字节数减去真正占用的字节数</para>
        /// </summary>
        /// <param name="bit">位深度</param>
        /// <param name="width">图片宽度</param>
        /// <returns>读取某行数据时需要跳过的字节数</returns>
        internal static int SkipBytes(int bit, int width)
        {
            return WidthBytes(bit * width) - width * (bit / 8);
        }

        /// <summary>
        /// 将颜色数换算成字节位
        /// </summary>
        /// <param name="colorCount">colorCount</param>
        /// <returns>字节位</returns>
        internal static int ColorCountToBitCount(int colorCount)
        {
            if (colorCount == 256) return 8;
            else if (colorCount == 65536) return 16;
            else if (colorCount == 16777216) return 24;
            else return 32;
        }
    }
}